package com.rxkj.mapper;

import com.rxkj.entity.sys.RoleEntity;
import com.rxkj.entity.sys.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserMapper {

    @Select("select su.*, sr.roleLevel as roleLevel from sys_user su, sys_role sr where su.Rid = sr.Id and su.Id = #{Id}")
    @ResultType(UserInfo.class)
    UserInfo getUserById(@Param("Id") Integer Id);

    @Select("select su.*, sr.roleLevel as roleLevel from sys_user su, sys_role sr where su.Rid = sr.Id and su.UserName = #{UserName}")
    @ResultType(UserInfo.class)
    UserInfo getUserByName(@Param("UserName") String userName);

    @Update("UPDATE sys_user SET userPwd = #{newPassword} WHERE id = #{Id}")
    @ResultType(Integer.class)
    Integer editPassword(@Param("Id") Integer id, @Param("newPassword") String newPassword);

    @Insert("INSERT INTO sys_user (gid, rid, userName, userPwd, userTel, email, userRemark,createTime)  VALUES  (1, #{rid},#{userName},#{userPwd},#{userTel},#{email},#{userRemark},#{createTime})")
    @ResultType(Integer.class)
    Integer insert(UserInfo userInfo);

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("INSERT INTO sys_role (gid,roleName,roleLevel,roleCode,roleRemark,createTime)  VALUES  (1,#{roleName},#{roleLevel},#{roleCode},#{roleRemark},now())")
    void addRole(RoleEntity roleEntity);

    @Select("select * from sys_role where id = #{id}")
    @ResultType(RoleEntity.class)
    RoleEntity getByIdRole(@Param("id") Integer id);

    Integer getTotalRows(UserInfo userInfo);

    Integer getTotalRole(RoleEntity roleEntity);

    List<UserInfo> getTotalUser(@Param("start") int start, @Param("end") int end, @Param("userInfo") UserInfo userInfo);

    List<RoleEntity> getRole(@Param("start") int start, @Param("end") int end, @Param("roleEntity") RoleEntity roleEntity);

    int updateByIdUser(UserInfo userInfo);

    int deleteUser(Integer id);

    int updateByIdRole(RoleEntity roleEntity);

    int deleteRole(Integer id);

    int deleteRolemenu(Integer id);

    int deleteRoleUser(Integer id);

    void addRoleMenus(Integer id, @Param("mid") List<Integer> mid);

    @Select("SELECT id FROM sys_menu")
    @ResultType(Integer.class)
    List<Integer> getMenuId();
}
